<?php 
class Application_Model_DbTable_Manufacture extends Zend_Db_Table_Abstract{
	protected $_name = "tbl_manufacture";
	protected $_primary = 'manufacture_id'; 
	protected $_dependentTables = array('Application_Model_DbTable_Product');
	
	//trả về mảng với key=id và value=name
	public function getPairColumn(){
		$select = $this->select()->order('manufacture_name asc');
		$result = $this->fetchAll($select)->toArray();
		$arr = array();
		foreach($result as $item){
			$arr[$item['manufacture_id']]=$item['manufacture_name'];
		}
		return $arr;
	}
	
	public function getList($filters = array(),$sortType = "ASC",$sortBy = null){
		$select = $this->select();
		if( count($filters) > 0 ){
			foreach($filters as $key => $value){
				if($key=="keyword" && trim($value)!=""){
					$select->where("manufacture_name like '%".$value."%'");
				}
				if($key=="fromDate" && $value!=null){
					$select->where('manufacture_creation_time >= ?',$value);
				}
				if($key=="toDate" && $value!=null){
					$select->where('manufacture_creation_time <= ?',$value);
				}
			}
		}
		if($sortBy==null){
			$sortBy = "manufacture_creation_time";
			$sortType = "Desc";
		}
		$select->order($sortBy . " " . $sortType);
		return $result = $this->fetchAll($select)->toArray();
	}
}
?>